/*
* @Author: nccloud
* @PageInfo: 表头编辑后事件
*/
import { ajax ,cardCache, getBusinessInfo, toast} from 'nc-lightapp-front';
import { byPkorgFiter } from '../../../../common/util/fiterUtils';
import { FIELDS, BUTTONID,AREA, URL, PAGECODE, CARDTABLEAREAIDS } from '../../constance';

let {setDefData, getDefData } = cardCache;

export default function(props,moduleId, key) {

        afterHeadEdit(props,moduleId, key);
}


export function afterHeadEdit(props,moduleId, key){
        if (key === FIELDS.pk_org) {
                props.resMetaAfterPkorgEdit(); // 选择主组织以后，恢复其他字段的编辑性
                props.button.setDisabled({
                        [BUTTONID.cardBody_1_AddLine]: false,
                        [BUTTONID.cardBody_2_AddLine]: false
                });
                filterByOrg(props, moduleId);
        }else if(key == 'vdef3'){
                javaAfterHeadEvent(props, key);
        }else if(key == 'costtype'){
                javaAfterHeadEvent(props, key);
        }
}

export function javaAfterHeadEvent(props, key){

        let bill = props.createExtCardData(PAGECODE.cardPagecode, AREA.cardFormId, CARDTABLEAREAIDS);

        let data = {
                key : key,
                bill : bill
        }

        ajax({
                url : URL.headAfterEdit,
                data : data,
                success: (res) => {
                        if(res.data && res.data.head){
                                //表头
                                props.form.setAllFormValue({ [AREA.cardFormId]: res.data.head[AREA.cardFormId] });
                        }
                }
                
        })
}

export function filterByOrg(props, moduleId){ 
        let value = props.form.getFormItemsValue(moduleId, 'pk_org'); 

        let pk_org = value.value;

        if(pk_org != null){

                byPkorgFiter(props, AREA.cardBody_1, 'sysid', pk_org, false);//系统账号
                byPkorgFiter(props, AREA.cardBody_1, 'name', pk_org, false);//姓名
                byPkorgFiter(props, AREA.cardBody_1, 'pk_psndoc', pk_org, false);//人员工号
                byPkorgFiter(props, AREA.cardBody_2, 'pk_psndoc', pk_org, false);//人员工号
        }

}